<?php

namespace app\admin\service;


use app\admin\model\ExploreRecord;
use think\facade\Db;

/**
 * 用户游历记录管理-服务类
 * @author 小树林
 * @since: 2024/11/22
 * Class ExploreRecordService
 * @package app\admin\service
 */
class ExploreRecordService extends BaseService
{
    /**
     * 构造函数
     * LevelService constructor.
     */
    public function __construct()
    {
        $this->model = new ExploreRecord();
    }

    /**
     * 获取数据列表
     * @return array
     * @since 2024/11/22
     * @author 小树林
     */
    public function getList()
    {
        $param = request()->param();

        //是否为远程搜索查询
        $is_query = $param['_is_query'] ?? '';
        if (!empty($is_query)) {
            return parent::query($param);
        }

        // 查询条件
        $map = [];

        // 有效标识
        $mark = isset($param['is_over']) ? (int)$param['is_over'] : 0;
        if ($mark) {
            $map[] = ['is_over', '=', $mark];
        }

        $nickname = getter($param,'nickname');
        if ($nickname) {
            $arr = Db::name("member")->where("nickname","like","%{$nickname}%")->column("id");
            $map[] = ['user_id', 'in', $arr];
        }

        $horsesName = getter($param,'horsesName');
        if ($horsesName) {
            $arr = Db::name("horses_config")->where("name","like","%{$horsesName}%")->column("id");
            $map[] = ['horses_id', 'in', $arr];
        }

        $field = '*';
        $with = [
            'with',
            [
                'member' => function ($query) {
                    $query->field('id,nickname');
                },
                'horses' => function ($query) {
                    $query->field('id,name');
                }
            ],
        ];
        $sort = '';
        return parent::getList($map, $field, $with, $sort); // TODO: Change the autogenerated stub
    }


}